#ifndef _DATAGRAMSOCKET_H_
#define _DATAGRAMSOCKET_H_

#include "net/Socket.hpp"
#include "net/SocketImpl.hpp"
#include "net/IPAddress.hpp"
#include "net/SocketAddress.hpp"

NET_NAMESPACE_BEGIN

/*
* UDP stream socket
*/
class CDatagramSocket : public CSocket
{
public:
	CDatagramSocket();
	explicit CDatagramSocket(CIPAddress::Family family);
	CDatagramSocket(const CSocketAddress& address, bool reuseAddress = false);
	CDatagramSocket(const CSocket& socket);
	~CDatagramSocket();
	CDatagramSocket& operator = (const CSocket& socket);

	void connect(const CSocketAddress& address);
	void bind(const CSocketAddress& address, bool reuseAddress = false);
	int sendBytes(const void* buffer, int length, int flags = 0);
	int receiveBytes(void* buffer, int length, int flags = 0);
	int sendTo(const void* buffer, int length, const CSocketAddress& address, int flags = 0);
	int receiveFrom(void* buffer, int length, CSocketAddress& address, int flags = 0);

	void setBroadcast(bool flag);
	bool getBroadcast() const;

protected:
	CDatagramSocket(CSocketImpl* pImpl);
};

NET_NAMESPACE_END

#endif
